package com.fafi.rxjava2.operatorbackpress;

import com.fafi.rxjava1.subscribeon.Switcher;
import com.fafi.rxjava2.backpress.Receiver;
import com.fafi.rxjava2.backpress.TelephonerOnCall;
import com.fafi.rxjava2.observeon.backpress.TelephonerCallbackOn;
import com.fafi.rxjava2.operator.Function;
import com.fafi.rxjava2.subscribeon.backpress.TelephonerCallOn;
import com.fafi.rxjava2.transform.back.TelephonerConverter;

public abstract class Telephoner<T> {
    public static <T> Telephoner<T> create(TelephonerOnCall<T> telephonerOnCall){
        return new TelephonerCreate<>(telephonerOnCall);
    }

    public void call(Receiver<T> receiver) { callActual(receiver);}

    protected abstract void callActual(Receiver<T> receiver);

    public <R> Telephoner<R> map(Function<T, R> function) {
        return new TelephonerMap<>(this, function);
    }

    public <R> Telephoner<R> lift(TelephonerOperator<R, T> telephonerOperator) {
        return new TelephonerLift<>(this, telephonerOperator);
    }

    public Telephoner<T> callOn(Switcher switcher) {
        return new TelephonerCallOn<>(this, switcher);
    }

    public Telephoner<T> callbackOn(Switcher switcher){
        return new TelephonerCallbackOn<>(this,switcher);
    }

    public <R> Telephoner<R> unify(TelephonerConverter<T, R> tTelephonerConverter) {
        return tTelephonerConverter.convert(this);
    }
}